The PhysicalPieceObserver script is a script that can be added onto GameObjects that you would like physical pieces to pair with and control the movement of.
The PhysicalPieceObserver script requires the Gameboard GameObject to be present. Find the Gameboard menu at the top of the unity header and click "Add SDK" to add the Gameboard GameObject to your project. If you do not have the Gameboard menu options, see Gameboard SDK Access
First, select all the GameObjects you would like to attach the PhysicalPieceObserver script to.
Next, find the Gameboard menu at the top of the unity header and click "Add Physical Piece Observer" to add the PhysicalPieceObserver to your GameObject(s).
This will add a the script to the gameobjects, and you will see a red gizmo indicating the pairing radius, and what on the gameobject is considered "forward".
Now that GameObject is able to quickly be paired with physical gameboard tokens!
You will notice the Physical Piece Observer Script has a few customizable options.
If the game object is in the world space, as opposed to the child of a canvas, you will want to set these options as well.
There are various events that you can use to keep track of physical token pairing and paired token locations:
Properties: GameboardShape
piece, bool
tokenAlreadyPaired, bool
currentlyPairedToToken
autopair
is off, this event will be triggered when a physical token is within the pairing radius of the GameObject. You will receive the GameboardShape
that describes the physical piece, and two flags idicating if the token is already paired, or if the gameobject is already paired to a token.Properties: GameboardShape
piece, List
reasons
autopair
is on, and allowPairOverriding
is off, this will be triggered anytime a piece is within pairing radius of a piece that it can't pair with for various reasons. You will get a list of enums describing the reason the token and GameObject was denied pairing.Properties: GameboardShape
piece
Properties: GameboardShape
piece
Properties: GameboardShape
piece
You can manually pair or unpair tokens as well.
To pair a GameboardShape
, you can call pairPiece
with an optional flag to overridePairing. Say you get a GameboardShape
from the OnPieceAvailableForPairing
event, and you decide you do want to pair this GameObject with that physical GameboardShape
. And you notice that token is already paired, but you displayed an alert asking if the user wants to continue and they clicked yes, so you want to proceed with the pairing.
objPieceObserver.pairPiece(shape, true);
and to remove a pairing simple call unpairPiece on the piece observer.
objPieceObserver.unpairPiece();
You can also see all the paired pieces by shapeId on the TouchController in the pairedPieces
dictionary. This pairs the GameboardShape
based on their shapeId to the PhyscialPieceObserver
they are currently paired with.